home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 141_01.zip / FCNPLOT.C < prev    next >
Text File  |  1993-06-01  |  3KB  |  98 lines

  1. /* fcnplot.c -- point-by-point plot of function(s) */
  2. /* 1984 apr 25 pmkrasno */
  3. #include "bdscio.h"
  4. #include "float.h"
  5. #define XSCALE "120.0" /* screen points, near full scale */
  6. #define YSCALE "90.0"
  7. #define WH 1    /* colors */
  8. #define BL 15
  9. #define MAXF 8
  10. #define wait pause () ; getchar () 
  11.  
  12. main ()    {    /* calc x, y & plot */
  13.     float x[241], y[2*241] ;
  14.     float *sine (), *cosine (), *expe (), *log (),
  15.         *exp10 (), *tangent (), *arctan(); 
  16.     float xscale[1], yscale[1], maxx[1], maxy[1] ;
  17.     float ulim[1], llim[1] ;
  18.     float delta[1], sx[1], sy[1], tx[1] ;
  19.     unsigned fno, lkup(), n, npts, secs1, secs2, nfcns ;
  20.     char inpf[60], inpx[60], inpy[60] ;
  21.     char *tbl[MAXF+1] ;
  22.     byte time1[13], time2[13], time3[13] ;
  23.     byte dif12[13+5], dif23[13+5] ;
  24.  
  25.     tbl[0] = "sin" ;    tbl[1] = "cos" ;
  26.     tbl[2] = "tan" ;    tbl[3] = "atan";
  27.      tbl[4] = "expe" ;    tbl[5] = "exp10" ;
  28.     tbl[6] = "log" ;    tbl[MAXF] = 0 ;
  29.     nfcns = 1 ; /* # functions */
  30.     while ( TRUE ) {
  31.     do {    printf ("Function ? ") ; scanf ("%s", inpf) ;
  32.         fno = lkup (inpf, tbl) ;
  33.         } while ( fno >= MAXF ) ;
  34.     printf ("Max x ? ") ; scanf ("%s", inpx) ;
  35.     atof (maxx, inpx) ;
  36.     printf ("Max y ? ") ; scanf ("%s", inpy) ;
  37.     atof (maxy, inpy) ;
  38.     atof (yscale, YSCALE) ;    atof (xscale, XSCALE) ;
  39.     fpdiv (delta, maxx, xscale) ;
  40.     fpdiv (xscale, xscale, maxx) ;
  41.     fpdiv (yscale, yscale, maxy) ;
  42.     fpchs (llim, maxx)  ; fpasg (ulim, maxx) ;
  43.     mode2 () ; cls (WH, BL) ;
  44.  
  45.     npts = 1 + ftoir (
  46.         fpdiv (tx, fpsub (tx, ulim, llim), delta)) ;
  47.         /* npts = 1 + ((ulim - llim) / delta) ; */
  48.     axes (0, 0) ;
  49.  
  50.     syst_d (time1) ; 
  51.     printf ("Evaluate %3d points: %s\N", 
  52.         nfcns * npts, time1) ;
  53.     comp_pts (npts, nfcns, x, y, llim, delta, 
  54.         fno == 0 ? sine :    fno == 1 ? cosine :
  55.         fno == 2 ? tangent :    fno == 3 ? arctan :
  56.         fno == 4 ? expe :    fno == 5 ? exp10 :
  57.         log ) ;
  58.         /* gawd, that's hideous - but I can't use an
  59.             array of pointers to functions. */
  60.  
  61.     syst_d (time2) ;
  62.     printf ("Plot %3d points:     %s\N", 
  63.         nfcns * npts, time2) ;
  64.     plot_pts (npts, nfcns, x, y, xscale, yscale) ;
  65.  
  66.     syst_d (time3) ;
  67.     printf ("Done :               %s\N", time3) ;
  68.     secs1 = tim_dif (dif12, time2, time1) ;
  69.     secs2 = tim_dif (dif23, time2, time3) ;
  70.     /* convert differences to seconds */
  71.     printf ("Evaluate: %d secs; Plot: %d secs\N", 
  72.         secs1, secs2) ;
  73.     } /* forever */
  74. } /* main */
  75.  
  76. float *log (res, xin) float *res, *xin ;    {
  77.     int sign ;    float *log10 () ;
  78.     log10 (res, &sign, xin) ;
  79.     if ( sign < 0 ) fpchs (res,res) ;
  80. /*
  81. printf ("log10 (%f) = %f\N", xin, res) ;
  82. */
  83.     return (res) ;
  84. } /* log */
  85.  
  86. unsigned lkup (str, tbl) char *str, **tbl ; { 
  87. /* lookup str in tbl, return number */
  88.     char *s, *t ;    int n ;
  89.     for (n = 0 ; **tbl ; ++tbl, ++n) /* each entry */
  90.         for (s = str, t = *tbl ; ; ++s, ++t)
  91.             if ( *s == '\0' ) return n ; /* hit */
  92.             else if ( toupper(*s) != toupper(*t) )
  93.                 break ;    /* miss, try next */
  94. } /* lkup */
  95.  
  96. f pointers to functions. */
  97.  
  98.